package com.itheima.controller;

import com.itheima.constant.MessageConstant;
import com.itheima.constant.RedisMessageConstant;
import com.itheima.entity.Result;
import com.itheima.utils.ValidateCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import redis.clients.jedis.JedisPool;

/*
类简介：

功能：

时间：2020/4/6

*/
@RequestMapping("validateCode")
@ResponseBody
@Controller
public class ValidateCodeController {

    @Autowired
    JedisPool jedisPool;

    @RequestMapping("send4Order")
    public Result sendValidateCodeForOrder(String telephone){

        String validateCode = ValidateCodeUtils.generateValidateCode(6).toString();

        System.out.println("validateCode = " + validateCode);

        jedisPool.getResource().setex(telephone + RedisMessageConstant.SENDTYPE_ORDER,600,validateCode);

        return new Result(true, MessageConstant.SEND_VALIDATECODE_SUCCESS);
    }

    @RequestMapping("send4Login")
    public Result sendValidateCodeForLogin(String telephone){

        String validateCode = ValidateCodeUtils.generateValidateCode(6).toString();

        System.out.println("validateCode = " + validateCode);

        jedisPool.getResource().setex(telephone + RedisMessageConstant.SENDTYPE_LOGIN,600,validateCode);

        return new Result(true, MessageConstant.SEND_VALIDATECODE_SUCCESS);
    }

}
